package cn.bdqn.crm.service;

import cn.bdqn.crm.domain.dao.BasDictMapper;
import cn.bdqn.crm.domain.dto.Page;
import cn.bdqn.crm.domain.pojo.BasDict;
import cn.bdqn.crm.domain.vo.BasDictVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class BasDictServiceImpl implements BasDictService {

    @Autowired
    private BasDictMapper basDictMapper;

    @Override
    public Page<BasDictVo> findByPage(Map<String, Object> mapCondition) throws Exception {
        int curpage = (Integer) mapCondition.get("pageNo");
        Integer pagesize = (Integer)mapCondition.get("pageSize");

        Integer total = basDictMapper.getBasDictCountByMap(mapCondition);
        Page<BasDictVo> pageBean = new Page<>(curpage,pagesize,total);
        mapCondition.put("beginPos",pageBean.getBeginPos());
        System.out.println("service:"+mapCondition);
        List<BasDict> pageList = basDictMapper.getBasDictListByMap(mapCondition);
        List<BasDictVo> list = new ArrayList<>();
        if(pageList.size()>0){
            for (BasDict dict:pageList) {
                BasDictVo bvo = new BasDictVo();
                bvo.setDictId(dict.getId());
                bvo.setDictItem(dict.getDictItem());
                bvo.setDictType(dict.getDictType());
                bvo.setDictValue(dict.getDictValue());
                String ret = dict.getDictIsEditable()==0?"否":"是";
                bvo.setIsEditable(ret);
                list.add(bvo);
            }
        }
        pageBean.setRows(list);
        return pageBean;
    }
}
